As an expression it has a comparative meaning, it is based on the situation of walking through a tunnel, supposedly dark, and seeing the clarity at the end indicating an exit; From there the light is interpreted as "the solution sought in the midst of a dark problem". However, there is another interpretation related to the near-death experience, where those who were able to return from 'clinical death' report having seen a tunnel with a very bright light at the end, which is supposed to be the final place where our soul travels; Although neurologists say it's just the effect of lack of oxygen on the brain.
In the popular saying, it refers to walking through the tunnel of a railway; seeing the light at the end of the tunnel, means that the darkness is over, or the uncertainty and the change or the end of the tunnel is near. What is ignored, is that that light could also be the train that advances towards the people who transit inside the tunnel.